$(function() {
	//var oTable1 = $('#entity_table').dataTable({
	//	// sAjaxSource : "/ware/list.do",
	//	// bServerSide: true,
	//	bProcessing : false,
	//	bAutoWidth : true,
	//	// "sScrollY": "200px",
	//	bPaginate : false,
	//	// sScrollY : "300px",
	//	bSort : true,
	//	bInfo : false,
	//	bLengthChange : false,
	//	bFilter : false,
	//	aoColumns : [ {
	//		bSortable : false
	//	}, {
	//		// "bVisible" : false
	//		bSortable : false
	//	}, null,null,null, {sWidth : 108}, {sWidth : 108}, {sWidth : 128}, {sWidth : 88}, {sWidth : 158}, {
	//		bSortable : false,
	//		sWidth : 78
	//	} ],
	//	aoColumnDefs: [
	//	{
	//	 sDefaultContent: '',
	//	 aTargets: [ '_all' ]
	//	  }
	//	],
	//	oLanguage : {
	//		sSearch : "搜索:",
	//		sLengthMenu : "每页显示 _MENU_ 条记录",
	//		sZeroRecords : "抱歉， 没有找到",
	//		sInfo : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
	//		sInfoEmpty : "没有数据",
	//		sInfoFiltered : "(从 _MAX_ 条数据中检索)",
	//		sZeroRecords : "没有检索到数据"
	//	}
	//});

	$("#serachBtn").click(function() {
		$("#searchcbox").show();
		$(this).after('<button type="button" id="_serachBtn" class="btn btn-white btn-info btn-bold"> <span class="glyphicon glyphicon glyphicon glyphicon-search"></span>搜索 </button>');
		$(this).remove();
		$("#firstInit").val("false");
	});

	$("#myButtons").on("click", "#_serachBtn", function() {
/*		var param = "";
		param += $.trim($("#newsTitleTxt").val()) == "" ? "" : ("&newsTitle=" + $.trim($("#newsTitleTxt").val()));
		param += $.trim($("#channelNameTxt").val()) == "" ? "" : ("&channelName=" + $.trim($("#channelNameTxt").val()));
		param += $.trim($("#authorTxt").val()) == "" ? "" : ("&author=" + $.trim($("#authorTxt").val()));

		window.location.href = "list.do?firstInit='false'" + param;*/
		$("#listForm").submit();

	});
	


	$(document).on('click', 'th input:checkbox', function() {
		var that = this;
		$(this).closest('table').find('tr > td:first-child input:checkbox').each(function() {
			// this.checked = that.checked;
			$(this).prop("checked", $(that).prop("checked"));
			var checked = $(this).prop("checked");
			if (checked === true)
				$(this).closest('tr').addClass('selected');
			else
				$(this).closest('tr').removeClass('selected');
		});
	});

	$('table tr > td:first-child input:checkbox').each(function() {
		var checked = $(this).prop("checked");
		if (checked === true)
			$(this).closest('tr').addClass('selected');
		else
			$(this).closest('tr').removeClass('selected');
	});

	$('tr > td:first-child input:checkbox').click(function() {
		var checked = $(this).prop("checked");
		if (checked === true)
			$(this).closest('tr').addClass('selected');
		else
			$(this).closest('tr').removeClass('selected');
	});

});

var List = (function() {
	return {
		editEntity : function($this) {
			var id = $($this).parents("tr").children('td').eq(1).html();
			window.location.href = root+"/user/input.do?id=" + id;
		},
		deleteEntity : function($this) {
			var id = $($this).parents("tr").children('td').eq(1).html();
			var r = confirm("确认要删除此客户吗？");
			if (r == true) {
				$.post(root+"/user/toTrash.do", {
					ids : id
				}, function(result) {
					if (result == "ok") {
						window.location.href = root+"/user/list.do?firstInit=" + $("#firstInit").val() + "&";
					} else {
						alert("删除出错了");
					}
				});
			}
		},
	}
})();

function add(){
	window.location.href = root+"/user/input.do";
}

function del(){
	ids = "";
	$('table tr > td:first-child input:checkbox').each(function() {
		if ($(this).prop("checked") === true) {
			ids += $.trim($(this).closest("tr").children('td').eq(1).html()) + ",";
		}
	});

	if (ids === "") {
		alert("请选择要删除的客户");
		return;
	}

	ids = ids.substring(0, ids.length - 1);
	var r = confirm("确认要删除这些客户吗？");
	if (r == true) {
		$.post(root+"/user/toTrash.do", {
			ids : ids
		}, function(result) {
			if (result == "ok") {
				window.location.href = root+"/user/list.do?firstInit=" + $("#firstInit").val() + "&";
				// oTable1.fnClearTable(0);
				// oTable1.fnDraw();
			} else {
				alert("删除出错了");
			}
		});
	}
}

function search(){
	$("#searchcbox").show();
	$("#searchBtn").after('<button type="button" id="_searchBtn" onClick="_search()" class="btn btn-white btn-info btn-bold"> <span class="glyphicon glyphicon glyphicon glyphicon-search"></span>搜索 </button>');
	$("#searchBtn").remove();
	$("#firstInit").val("false");
}
function _search(){
	/*		var param = "";
	param += $.trim($("#newsTitleTxt").val()) == "" ? "" : ("&newsTitle=" + $.trim($("#newsTitleTxt").val()));
	param += $.trim($("#channelNameTxt").val()) == "" ? "" : ("&channelName=" + $.trim($("#channelNameTxt").val()));
	param += $.trim($("#authorTxt").val()) == "" ? "" : ("&author=" + $.trim($("#authorTxt").val()));

	window.location.href = "list.do?firstInit='false'" + param;*/
	$("#listForm").submit();
}